<?php
class User extends AppModel
{
    var $name = 'User';
    var $validate = array(
     			'name' => array(
     				'rule1' => array('rule' => 'isUnique','message' => 'このユーザ名はすでに使用されています。'),
     				'rule2' => array('rule' => VALID_NOT_EMPTY, 'message' => 'ユーザ名を入力してください'),
     			),
                'password' => array('rule' => VALID_NOT_EMPTY, 'message' => 'パスワードを入力してくだっさい')
     );
	function beforeSave() {
		//debug($this->data['Login']);
		//unset($this->data['Login']['password']);
		/*
		if(!empty($this->data['Login']['password'])){
			$this->data['Login']['password'] =  sha1($this->data['Login']['password']);
			debug($this->data['Login']);
			return true;
		}else{
			return true;
		}
		*/
		return true;
	}
	function beforeDelete(){
		$this->data = $this->find('first', array(
            'recursive' => 0,
            'conditions' => array($this->name . '.id' => $this->id)
        ));
        if( $this->data['User']['name'] == 'dave' ){
        	throw new Exception("dave を削除することはできません");
        	return false;
        }else{
        	return true;
        }
	}
}
?>